<?php                                                                                                                                                                     
/* -------------------------------------------------------------------------
 * File Name : inc_header.phtml
 * -------------------------------------------------------------------------                                                                                              
 */

//Check if admin
include_once(SITE_ROOT . '/inc/class_db.php');
	
//SQL
$db = New Database;

// Get user adm
if (!empty($_COOKIE['cookie_login'])) {
	$sql = "SELECT admin FROM users WHERE `nom`='".$_COOKIE['cookie_login']."'";
}
else {
	$sql = "SELECT admin FROM users WHERE `nom`='".$_SESSION['login']."'";
}

$db->select_query($sql);
$row = $db->retourLigne();
$admin = $row['admin'];

//Current page
$path = $_SERVER['PHP_SELF'];
$page = basename ($path);

if ($_SESSION['mobile'] !== 'mobile') {
	if ($admin == '0') {
$menu = <<<EOT
		<nav>
			<a href="../front/accueil.php" data-page="accueil.php">Accueil</a>
			<a href="../front/profil.php" data-page="profil.php">Profil</a>
			<a href="../front/logout.php" data-page="logout.php">Sortir</a>
		</nav>
EOT;
	}
	else {
$menu = <<<EOT
		<nav>
			<a href="../front/accueil.php" data-page="accueil.php">Accueil</a>
			<a href="../front/profil.php" data-page="profil.php">Profil</a>
			<a href="../front/admin.php" data-page="admin.php">Admin</a>
			<a href="../front/logout.php" data-page="logout.php">Sortir</a>
		</nav>
EOT;
	}
}
else {
        if ($admin == '0') {
$menu = <<<EOT
                <nav>
                        <a href="../front/accueil.php" data-page="accueil.php">Accueil</a>
                        <a href="../front/flux.php" data-page="flux.php">Flux</a>
			<a href="../front/profil.php" data-page="profil.php">Profil</a>
                        <a href="../front/logout.php" data-page="logout.php">Sortir</a>
                </nav>
EOT;
        }
        else {
$menu = <<<EOT
                <nav>
                        <a href="../front/accueil.php" data-page="accueil.php">Accueil</a>
			<a href="../front/flux.php" data-page="flux.php">Flux</a>
                        <a href="../front/profil.php" data-page="profil.php">Profil</a>
                        <a href="../front/admin.php" data-page="admin.php">Admin</a>
                        <a href="../front/logout.php" data-page="logout.php">Sortir</a>
                </nav>
EOT;
        }
}

$nav = simplexml_load_string($menu);


foreach($nav AS $key => $link) {
    if ($link['data-page']==$page) {
        $link->addAttribute('class', 'active');
    }
}
echo str_replace('<?xml version="1.0"?>','', $nav->asXml());

?>
